﻿'***********************************************************************
' Assembly         : SOFA.Caching
' Copyright        : (c) Jebarson. All rights reserved.
' Website			: http://www.jebarson.info
'***********************************************************************

Namespace Caching.StaticStore

    ''' <summary>
    ''' Config for the static storage.
    ''' </summary>
    Public Class StaticStorageConfig
        Implements ICacheStorageConfig

#Region " Declarations "
        ''' <summary>
        ''' Member variable for refresh time.
        ''' </summary>
        Private refreshTimeValue As TimeSpan

        ''' <summary>
        ''' Member variable for cache priority.
        ''' </summary>
        Private defaultCachePriorityValue As CachePriority

        ''' <summary>
        ''' Member variable for default config.
        ''' </summary>
        Private Shared defaultConfigValue As StaticStorageConfig

        ''' <summary>
        ''' Member variable for static storage.
        ''' </summary>
        Private storageValue As StaticStorage(Of StaticStorageConfig)
#End Region

#Region " ICacheStorageConfig Support "
        ''' <summary>
        ''' Gets or sets the default cache priority.	
        ''' </summary>
        ''' <value>The default cache priority.</value>
        Public Property DefaultCachePriority() As CachePriority Implements ICacheStorageConfig.DefaultCachePriority
            Get
                Return Me.defaultCachePriorityValue
            End Get
            Set(ByVal value As CachePriority)
                Me.defaultCachePriorityValue = value
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the refresh time.	
        ''' </summary>
        ''' <value>The refresh time.</value>
        Public Property RefreshTime() As TimeSpan Implements ICacheStorageConfig.RefreshTime
            Get
                Return Me.refreshTimeValue
            End Get
            Set(ByVal value As TimeSpan)
                Me.refreshTimeValue = value
            End Set
        End Property
#End Region

#Region " Public Properties "
        ''' <summary>
        ''' Gets or sets the default config.	
        ''' </summary>
        ''' <value>The default config.</value>
        Public Shared Property DefaultConfig() As StaticStorageConfig
            Get
                If defaultConfigValue Is Nothing Then
                    CreateDefaultConfig()
                End If
                Return defaultConfigValue
            End Get
            Private Set(ByVal value As StaticStorageConfig)
                defaultConfigValue = value
            End Set
        End Property

        ''' <summary>
        ''' Gets the storage.	
        ''' </summary>
        ''' <returns>The storage.</returns>
        Public ReadOnly Property Storage() As ICacheStorage(Of ICacheStorageConfig) Implements ICacheStorageConfig.Storage
            Get
                If Me.storageValue Is Nothing Then
                    Me.storageValue = StaticStorage(Of StaticStorageConfig).Instance
                End If
                Return Me.storageValue
            End Get
        End Property
#End Region

#Region " Private Methods "
        ''' <summary>
        ''' Creates the default config. Cache priority is normal and refresh time is 4 hours.
        ''' </summary>
        Private Shared Sub CreateDefaultConfig()
            defaultConfigValue = New StaticStorageConfig

            With defaultConfigValue
                .DefaultCachePriority = CachePriority.Normal
                .RefreshTime = New TimeSpan(4, 0, 0)
            End With
        End Sub
#End Region

    End Class

End Namespace
